<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>修改销售订单</title>
	<link href="<%=path%>/css/style_min.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/core.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/form.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/list.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/CustomerSelect.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/UsersSelect.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xWindowPanel.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xToolbar.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
    input { width: 180px;}
    textarea { width: 503px; height: 40px;}
    select { width: 188px;}
    .n { text-align: right;}
    </style>
  </head>
  <body>
    <form name="salesOrderForm" id="salesOrderForm" action="<%=path%>/sales/salesOrder/update.t4m" class="form" method="post">
      <div class="form-group">基本信息</div>
      <table class="form-table" cellspacing="0" cellpadding="0" width="100%">
        <tr>
          <td class="form-left"><span class="form-required">*</span>订单编号</td>
          <td class="form-right"><s:textfield name="salesOrder.code" cssClass="text" readonly="true"></s:textfield></td>
          <td class="form-left">销售人员</td>
          <td class="form-right"><s:hidden name="salesOrder.saler.id" id="salerId"></s:hidden></td>
        </tr>
        <tr>
          <td class="form-left"><span class="form-required">*</span>选择客户</td>
          <td class="form-right"><s:hidden name="salesOrder.customer.id" id="customerId"></s:hidden></td>
          <td class="form-left"><span class="form-required">*</span>订单日期</td>
          <td class="form-right"><input type="text" name="salesOrder.orderDate" class="Wdate text f" onclick="new WdatePicker();" value="<s:property value="salesOrder.orderDate"/>"/></td>
        </tr>
        <tr>
        	<!-- 
	          <td class="form-left">开票类型</td>
	          <td class="form-right"><s:select name="customer.billType.id" list="billTypeList" listKey="id" listValue="name" disabled="true"/></td>
          	 -->
          <td class="form-left">发票编号</td>
          <td class="form-right"><s:textfield name="salesOrder.billCode" cssClass="text"></s:textfield></td>
          <td class="form-left"><span class="form-required">*</span>收货地址</td>
          <td class="form-right"><s:textfield name="salesOrder.takeAddress" cssClass="text required"></s:textfield></td>
        </tr>
        <tr>
        </tr>
        <tr>
          <td class="form-left">备注</td>
          <td class="form-right" colspan="3"><s:textarea name="salesOrder.remark" cssClass="textarea"></s:textarea></td>
        </tr>
      </table>
      
      <div class="form-group">销售订单明细</div>
      <div id="toolbar"></div>
      <table id="titleTable" cellpadding="0" cellspacing="0">
        <tr>
          <td>货品编号</td>
          <td>货品名称</td>
          <td>规格型号</td>
          <td>库存数量</td>
          <td><span class="required">*</span>销售数量(个)</td>
          <td><span class="required">*</span>销售单价(元)</td>
          <td><span class="required">*</span>合计(元)</td>
          <td>取消</td>
        </tr>
      </table>
		<div style="overflow-y: scroll; height: 180px">
      <table id="dataTable" cellpadding="0" cellspacing="0">
        <s:iterator id="item" value="itemList" status="st">
          <tr class="row" id="<s:property value="#item.id"/>">
            <input type="hidden" name="saleOrderProductIdList" value="<s:property value="#item.id"/>"/>
            <td><span><s:property value="#item.product.code"/></span>
            	<input type="hidden" name="productIdList" value="<s:property value="#item.product.id"/>"/>
            </td>
            <td><span><s:property value="#item.product.name"/></span></td>
            <td><span><s:property value="#item.product.standard"/></span></td>
            <td><span><s:property value="#item.stock.amounts"/></span>
            	<input type="hidden" name="stockIdList" value="<s:property value="#item.stock.id"/>"/></td>
            <td><input type="text" style="width:62px;text-align:right;margin-left:0px;" class="text n required" id="amount<s:property value="#st.index"/>" name="saleAmountsList" onblur="sumPrice(<s:property value="#st.index"/>,this,'price<s:property value="#st.index"/>')" value="<s:property value="#item.amounts"/>"/></td>
            <td><input type="text" style="width:62px;text-align:right;margin-left:0px;" class="text n required" id="price<s:property value="#st.index"/>" name="salePriceList" onblur="sumPrice(<s:property value="#st.index"/>,this,'amount<s:property value="#st.index"/>')" value="<s:property value="#item.salesPrice"/>"/></td>
            <td id="td_<s:property value="#st.index"/>"><span><s:property value="#item.lastPrice"/></span></td>
            <td><div class="quick-button" style="background-position: -39px 0px;" onclick="delData('<s:property value="#item.id"/>')"></div></td>
          </tr>
        </s:iterator>
      </table>
      </div>
      <s:hidden name="salesOrder.id"/>
      <s:hidden name="tabId"/>
      <s:hidden name="windowPanelId"/>
    </form>
    <script src="<%=path%>/js/prototype_for_validation.js" type="text/javascript"></script>
    <script src="<%=path%>/js/validation_cn.js" type="text/javascript"></script>
    <script src="<%=path%>/js/core.js" type="text/javascript"></script>
    <script src="<%=path%>/js/share.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Validate.js" type="text/javascript"></script>
    <script src="<%=path%>/js/datePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="<%=path%>/js/CustomerSelect.js" type="text/javascript"></script>
    <script src="<%=path%>/js/UsersSelect.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xWindowPanel.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Draggable.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.items.js" type="text/javascript"></script>
    <script src="<%=path%>/js/modules/stock.js" type="text/javascript"></script>
    <script src="<%=path%>/js/modules/product/product.js" type="text/javascript"></script>
	<script src="<%=path%>/js/Grid.js" type="text/javascript"></script>
    <script type="text/javascript" src="<%=path%>/js/BoxSelect.js"></script>
	<script src="<%=path%>/js/jquery-impromptu.js" type="text/javascript"></script>
    <script type="text/javascript">
    var valid = new Validation('salesOrderForm',{immediate:true});
    var indexNum=0,grid;
    
    $(document).ready(function(){
    	new Toolbar({
            renderTo : 'toolbar',
            icon: '../../image/op.gif',
            border:'both',
            items : [{
              type : 'button',
              text : '自有商品',
              tip : '提取销售货品',
              useable : 'T',
              position: {
                a: '0px 0px',
                b: '0px -120px'
              },
              handler : function(){
              	stock.choose();
              }
            },"-",{
                type : 'button',
                text : '外购商品',
                tip : '提取销售货品',
                useable : 'T',
                position: {
                  a: '0px 0px',
                  b: '0px -120px'
                },
                handler : function(){
                    productFunctions.chooseForSales();
                }
              }]
          });
      
      grid = new Grid({
        titleTable:'titleTable',
        dataTable:'dataTable',
        widths : [120,100,85,85,85,85,70,39],
        height : 290
      });
      
      loadReady();
      new CustomerSelect({
          url : '<%=path%>/system/ajax/listCustomerByCondition.t4m',
          inputId : 'customerId',
          title : '选择客户',
          width : 184,
          multiple : false,
          selected : $('#customerId').val()
        });
      new UsersSelect({
        url : '<%=path%>/system/ajax/listUsersByCondition.t4m',
        inputId : 'salerId',
        title : '选择销售员',
        width : 184,
        multiple : false,
        selected : $('#salerId').val()
      });
    });
    
    $('#dataTable tr.row').each(function(){
      ++indexNum;
    });
    
    function addData(dataArray) {
        var table = $('#dataTable');
        for(var i=0,len=dataArray.length; i<len; ++i){
          if($('#'+dataArray[i].id).length){
            continue;
          }
          var htmlString = [];
          htmlString.push('<tr class="row" id="'+dataArray[i].id+'">');
          htmlString.push('<td><span>'+dataArray[i].pCode+'</span></td>');
          htmlString.push('<td><span>'+dataArray[i].pName+'</span></td>');
          htmlString.push('<td><span>'+dataArray[i].pStandard+'</span></td>');
          htmlString.push('<td><span>'+dataArray[i].stockAmounts+'</span></td>');
          htmlString.push('<td><input type="text" class="text n required"  name="saleAmountsList" id="amount'+indexNum+'" onblur="sumPrice(\''+ indexNum + '\',this,\'price'+indexNum+'\')" style="width:62px;text-align:right;margin-left:0px;"/></td>');
          htmlString.push('<td><input type="text" class="text n required"  name="salePriceList" id="price'+indexNum+'" onblur="sumPrice(\''+ indexNum + '\',this,\'amount'+indexNum+'\')" style="width:62px;text-align:right;margin-left:0px;"/></td>');
          htmlString.push('<td id="td_' + indexNum + '">&nbsp;</td>');
          htmlString.push('<td><div align="center" class="quick-button" style="background-position: -39px 0px;" onclick="delData(\''+dataArray[i].id+'\')"></div></td>');
          htmlString.push('<input type="hidden" name="stockIdList" value="'+dataArray[i].id+'"/>');
          htmlString.push('<input type="hidden" name="productIdList" value="'+dataArray[i].pId+'"/>');
          htmlString.push('</tr>');
          table.append(htmlString.join(''));
          indexNum++;
        }
        if(grid){
         grid.updateWidth();
        }
      }
    
    function sumPrice(arg0,arg1,arg2){
  	  var value1 = arg1.value;
  	  var value2 = document.getElementById(arg2).value;
  	  $("#td_" + arg0).html(value1 * value2);
    } 
      
      function delData(id) {
        $('#'+id).remove();
        indexNum--;
      }
    </script>
  </body>
</html>